package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateRoomTypeDialog;
import pl.prv.polanie.client.dto.CSRoomTypeDTO;
import pl.prv.polanie.client.dto.CSVRoomTypeDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableRoomTypes;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class RoomTypesList extends ObjectsList {

	TableRoomTypes tableRoomTypes= new TableRoomTypes(this);
	
	public RoomTypesList() {
		
		CSRoomTypeDTO[] ls = Cache.getAllRoomTypes();
		
		add(tableRoomTypes);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSRoomTypeDTO cs = ls[i];
			CSVRoomTypeDTO csv = ViewDataProvider.getCSVRoomType(cs);
			
			tableRoomTypes.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateRoomTypeDialog cstd = new CreateRoomTypeDialog(RoomTypesList.this, null); 
				cstd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableRoomTypes.removeSelectedRoomTypeFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSRoomType(CSRoomTypeDTO csRoomType) {
		tableRoomTypes.saveOrUpdateRoomTypeInTable(csRoomType);
	}
	
	public void removeSelectdCSLecturer() {
		tableRoomTypes.removeSelectedRoomTypeFromTable();
	}

}
